package com.dfrz.entity;

import com.dfrz.common.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author 29877
 * 统一返回结果类
 */
@Data
public class Result<T> implements Serializable {
    private Integer code;    //相应状态码
    private String msg;     //相应消息
    private T data;         //响应数据

    //操作ok
    private Result(){}
    public static <T> Result<T> success(T data){
        Result<T> result =new Result<>();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        result.setData(data);
        return result;
    }

    /**
     * 操作失败
     */
    public static <T> Result<T> error(Integer code,String msg){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    /**
     * 操作异常
     * @param
     */
    public static <T> Result<T> exception(Integer code,String msg){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }
}
